
/***  DOCUMENTATION LAYER

	Javascript Function Library Template

	Last Update: Aug 2007
	Author: Tom at klenwell@gmail.com
	License: GPL License

FUNCTIONS	
	balance_doms(ArrayIds)
	vcenter_dom_in_window(id)
	get_window_height()
  get_max(ArraySet)

NOTES
	To link: <script type="text/javascript" src="path/to/file.js"></script>

REFERENCE
	http://developer.mozilla.org/en/docs/JavaScript
	LGPL License: http://www.opensource.org/licenses/lgpl-license.php
	GPL License: http://www.opensource.org/licenses/gpl-license.php

______________________________________________________________________________*/

// balance doms
/*
	balance n sibling elements.  argument must be js array.  sample usage:
  
    balance_doms(['id1', 'id2', 'id3']);
*/
/*____________________________________________________________________________*/
function balance_doms(ArrayIds)
{
  var Doms = new Array();
  var DomHeights = new Array();
  for ( i=0; i<ArrayIds.length; i++ )
  {
    if ( document.getElementById(ArrayIds[i]) )
    {
      Doms[i] = document.getElementById(ArrayIds[i]);
      DomHeights[i] = Doms[i].offsetHeight;
    }
  }
  
  var max_ht = get_max(DomHeights);
  
  for ( i=0; i<Doms.length; i++ )
  {
    Doms[i].style.height = max_ht + "px";
  }
  
  // debug
  //alert("max ht is " + max_ht);
  
  return;  
}
/*____________________________________________________________________________*/


// vertically center page
/*____________________________________________________________________________*/
function vcenter_dom_in_window(id)
{
  var DomId = document.getElementById(id);
  var DomHt = DomId.offsetHeight;
  var BodyHt = get_window_height();
  
  var TopOffset = Math.floor(( BodyHt - DomHt ) / 2);
  TopOffset = TopOffset + "px";
  
  // debug
  //alert("BodyHt / DomHt / TopOffset : " + BodyHt + " / " + DomHt + " / " + TopOffset);
  
  DomId.style.marginTop = TopOffset;
  return;
}
/*____________________________________________________________________________*/


// get window height
// source: http://www.howtocreate.co.uk/tutorials/javascript/browserwindow 
/*____________________________________________________________________________*/
function get_window_height() 
{
  var window_height = 600;
  var debug = true;
  
  // Non-IE
  if ( typeof( window.innerHeight ) == 'number' ) window_height = window.innerHeight;

  // IE 6+ in 'standards compliant mode'
  else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
  {
    window_height = document.documentElement.clientHeight;
  }
  // IE 4 compatible
  else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
  {
    window_height = document.body.clientHeight;
  }
  // not recognized
  else if ( debug ) alert('window size not found');
  
  return window_height;
}
/*____________________________________________________________________________*/


// get max value in array 
/*____________________________________________________________________________*/
function get_max(ArraySet)
{
  compareNumbers = function(a, b) { return a - b; }
  ArraySet.sort(compareNumbers);
  ArraySet.reverse();
  return ArraySet[0];  
}
/*____________________________________________________________________________*/

